<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../../styles/base/base.css" type="text/css" media="screen" />
</head>
<body style="background-color:#eeeeee;">
<pre style="color:#000000; background-color:#eeeeee; font-size:8pt; font-family:'Courier New';"><span style="color:#303030">   1 </span><span style="color:#bb7977; font-weight:bold">package</span> no<span style="color:#ff0080; font-weight:bold">.</span>knowit<span style="color:#ff0080; font-weight:bold">.</span>helloseam<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   2 </span><span style="color:#bb7977; font-weight:bold">import</span> org<span style="color:#ff0080; font-weight:bold">.</span>jboss<span style="color:#ff0080; font-weight:bold">.</span>seam<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#0080c0">Component</span><span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   3 </span><span style="color:#bb7977; font-weight:bold">import</span> org<span style="color:#ff0080; font-weight:bold">.</span>jboss<span style="color:#ff0080; font-weight:bold">.</span>seam<span style="color:#ff0080; font-weight:bold">.</span>log<span style="color:#ff0080; font-weight:bold">.</span>LogProvider<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   4 </span><span style="color:#bb7977; font-weight:bold">import</span> org<span style="color:#ff0080; font-weight:bold">.</span>jboss<span style="color:#ff0080; font-weight:bold">.</span>seam<span style="color:#ff0080; font-weight:bold">.</span>log<span style="color:#ff0080; font-weight:bold">.</span>Logging<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   5 </span><span style="color:#bb7977; font-weight:bold">import</span> org<span style="color:#ff0080; font-weight:bold">.</span>testng<span style="color:#ff0080; font-weight:bold">.</span>Assert<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   6 </span><span style="color:#bb7977; font-weight:bold">import</span> org<span style="color:#ff0080; font-weight:bold">.</span>testng<span style="color:#ff0080; font-weight:bold">.</span>annotations<span style="color:#ff0080; font-weight:bold">.</span>BeforeSuite<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   7 </span><span style="color:#bb7977; font-weight:bold">import</span> org<span style="color:#ff0080; font-weight:bold">.</span>testng<span style="color:#ff0080; font-weight:bold">.</span>annotations<span style="color:#ff0080; font-weight:bold">.</span>Test<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">   8 </span>
<span style="color:#303030">   9 </span><span style="color:#bb7977; font-weight:bold">import</span> no<span style="color:#ff0080; font-weight:bold">.</span>knowit<span style="color:#ff0080; font-weight:bold">.</span>seam<span style="color:#ff0080; font-weight:bold">.</span>openejb<span style="color:#ff0080; font-weight:bold">.</span>mock<span style="color:#ff0080; font-weight:bold">.</span>SeamOpenEjbTest<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">  10 </span>
<span style="color:#303030">  11 </span><span style="color:#bb7977; font-weight:bold">public class</span> HelloSeamTest <span style="color:#bb7977; font-weight:bold">extends</span> <strong style="color:green">SeamOpenEjbTest</strong> <span style="color:#ff0080; font-weight:bold">{</span>
<span style="color:#303030">  12 </span>  <span style="color:#bb7977; font-weight:bold">private static final</span> <span style="color:#0080c0">String</span>  EXPECTED_HELLO <span style="color:#ff0080; font-weight:bold">=</span> <span style="color:#a68500">&quot;hello&quot;</span><span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">  13 </span>  <span style="color:#bb7977; font-weight:bold">private static final</span> LogProvider log <span style="color:#ff0080; font-weight:bold">=</span> Logging<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">getLogProvider</span><span style="color:#ff0080; font-weight:bold">(</span>SeamOpenEjbTest<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#bb7977; font-weight:bold">class</span><span style="color:#ff0080; font-weight:bold">);</span>
<span style="color:#303030">  14 </span>
<span style="color:#303030">  15 </span>  &#64;Override
<span style="color:#303030">  16 </span>  &#64;BeforeSuite
<span style="color:#303030">  17 </span>  <span style="color:#bb7977; font-weight:bold">public</span> <span style="color:#8080c0; font-weight:bold">void</span> <span style="color:#004466">beforeSuite</span><span style="color:#ff0080; font-weight:bold">()</span> <span style="color:#bb7977; font-weight:bold">throws</span> <span style="color:#0080c0">Exception</span> <span style="color:#ff0080; font-weight:bold">{</span>
<span style="color:#303030">  18 </span>    <span style="color:#f27900">// Change some logging, INFO|DEBUG|WARN|ERROR|FATAL</span>
<span style="color:#303030">  19 </span>    contextProperties<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">put</span><span style="color:#ff0080; font-weight:bold">(</span><span style="color:#a68500">&quot;log4j.category.no.knowit.seam.openejb.mock&quot;</span><span style="color:#ff0080; font-weight:bold">,</span> <span style="color:#a68500">&quot;DEBUG&quot;</span><span style="color:#ff0080; font-weight:bold">);</span>
<span style="color:#303030">  20 </span>    contextProperties<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">put</span><span style="color:#ff0080; font-weight:bold">(</span><span style="color:#a68500">&quot;log4j.category.no.knowit.helloseam&quot;</span><span style="color:#ff0080; font-weight:bold">,</span> <span style="color:#a68500">&quot;debug&quot;</span><span style="color:#ff0080; font-weight:bold">);</span>
<span style="color:#303030">  21 </span>    <span style="color:#bb7977; font-weight:bold">super</span><span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">beforeSuite</span><span style="color:#ff0080; font-weight:bold">();</span>
<span style="color:#303030">  22 </span>  <span style="color:#ff0080; font-weight:bold">}</span>
<span style="color:#303030">  23 </span>
<span style="color:#303030">  24 </span>  &#64;Test
<span style="color:#303030">  25 </span>  <span style="color:#bb7977; font-weight:bold">public</span> <span style="color:#8080c0; font-weight:bold">void</span> <span style="color:#004466">shouldSayHelloToSeam</span><span style="color:#ff0080; font-weight:bold">()</span> <span style="color:#bb7977; font-weight:bold">throws</span> <span style="color:#0080c0">Exception</span> <span style="color:#ff0080; font-weight:bold">{</span>
<span style="color:#303030">  26 </span>
<span style="color:#303030">  27 </span>    <span style="color:#bb7977; font-weight:bold">new</span> <span style="color:#004466">ComponentTest</span><span style="color:#ff0080; font-weight:bold">() {</span>
<span style="color:#303030">  28 </span>      &#64;Override
<span style="color:#303030">  29 </span>      <span style="color:#bb7977; font-weight:bold">protected</span> <span style="color:#8080c0; font-weight:bold">void</span> <span style="color:#004466">testComponents</span><span style="color:#ff0080; font-weight:bold">()</span> <span style="color:#bb7977; font-weight:bold">throws</span> <span style="color:#0080c0">Exception</span> <span style="color:#ff0080; font-weight:bold">{</span>
<span style="color:#303030">  30 </span>        <span style="color:#0080c0">Object</span> instance <span style="color:#ff0080; font-weight:bold">=</span> <span style="color:#0080c0">Component</span><span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">getInstance</span><span style="color:#ff0080; font-weight:bold">(</span><span style="color:#a68500">&quot;helloSeam&quot;</span><span style="color:#ff0080; font-weight:bold">);</span>
<span style="color:#303030">  31 </span>        assert instance <span style="color:#ff0080; font-weight:bold">!=</span> null <span style="color:#ff0080; font-weight:bold">:</span> <span style="color:#a68500">&quot;Component.getInstance(</span><span style="color:#ff00ff; font-weight:bold">\&quot;</span><span style="color:#a68500">&quot;</span> <span style="color:#ff0080; font-weight:bold">+</span> <span style="color:#a68500">&quot;helloSeam&quot;</span> <span style="color:#ff0080; font-weight:bold">+</span> <span style="color:#a68500">&quot;</span><span style="color:#ff00ff; font-weight:bold">\&quot;</span><span style="color:#a68500">) returned null&quot;</span><span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">  32 </span>        assert instance <span style="color:#bb7977; font-weight:bold">instanceof</span> HelloSeam <span style="color:#ff0080; font-weight:bold">:</span> <span style="color:#a68500">&quot;Component.getInstance(</span><span style="color:#ff00ff; font-weight:bold">\&quot;</span><span style="color:#a68500">&quot;</span> <span style="color:#ff0080; font-weight:bold">+</span> <span style="color:#a68500">&quot;helloSeam&quot;</span> <span style="color:#ff0080; font-weight:bold">+</span> <span style="color:#a68500">&quot;</span><span style="color:#ff00ff; font-weight:bold">\&quot;</span><span style="color:#a68500">) returned incorrect type&quot;</span><span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">  33 </span>
<span style="color:#303030">  34 </span>        HelloSeam helloSeam <span style="color:#ff0080; font-weight:bold">= (</span>HelloSeam<span style="color:#ff0080; font-weight:bold">)</span>instance<span style="color:#ff0080; font-weight:bold">;</span>
<span style="color:#303030">  35 </span>        Assert<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">assertEquals</span><span style="color:#ff0080; font-weight:bold">(</span>EXPECTED_HELLO<span style="color:#ff0080; font-weight:bold">,</span> helloSeam<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">sayHello</span><span style="color:#ff0080; font-weight:bold">(),</span> <span style="color:#a68500">&quot;helloSeam.sayHello:&quot;</span><span style="color:#ff0080; font-weight:bold">);</span>
<span style="color:#303030">  36 </span>        log<span style="color:#ff0080; font-weight:bold">.</span><span style="color:#004466">debug</span><span style="color:#ff0080; font-weight:bold">(</span><span style="color:#a68500">&quot;**** Seam says Hello :-)&quot;</span><span style="color:#ff0080; font-weight:bold">);</span>
<span style="color:#303030">  37 </span>      <span style="color:#ff0080; font-weight:bold">}</span>
<span style="color:#303030">  38 </span>    <span style="color:#ff0080; font-weight:bold">}.</span><span style="color:#004466">run</span><span style="color:#ff0080; font-weight:bold">();</span>
<span style="color:#303030">  39 </span>  <span style="color:#ff0080; font-weight:bold">}</span>
<span style="color:#303030">  40 </span><span style="color:#ff0080; font-weight:bold">}</span>
</pre>
</body>
</html>
